package colors;

import javax.microedition.lcdui.Graphics;

/**
 * <p>Abstract class to serve as base for all colors the User may use in programming
 * with this library.</p>
 * 
 * @author Shayne Caswell
 *
 */
abstract public class MobileColor {
	/**	The value of red for this color, 0 to 255 inclusive */
	private int red;
	
	/**	The value of green for this color, 0 to 255 inclusive */
	private int green;
	
	/**	The value of blue for this color, 0 to 255 inclusive */
	private int blue;
	
	/**
	 * Instantiate a color with the given red, blue, green values.
	 * 
	 * @param red Integer representing the red in this color, 0 to 255 inclusive
	 * @param green Integer representing the green in this color, 0 to 255 inclusive
	 * @param blue Integer representing the blue in this color, 0 to 255 inclusive
	 */
	public MobileColor(int red, int green, int blue){
		if(red > 255 || green > 255 || blue > 255 || red < 0 || green < 0 || blue < 0){
			this.red = 0;
			this.blue = 0;
			this.green = 0;
		} else {
			this.red = red;
			this.blue = blue;
			this.green = green;
		}
	}
	
	/**
	 * Convenience method to make setting the paint color of a <code>Graphics</code>
	 * object simpler for less experienced users. Also reduces the code required to
	 * enact such a change by a number of lines.
	 * 
	 * @param g The <code>Graphics</code> object that is having its paint color changed.
	 */
	public void setToThisColor(Graphics g){
		g.setColor(this.red, this.green, this.blue);
	}
	
	/**
	 * Conveniently create a color opposite of this one.
	 * 
	 * @return The <code>Mixed</code> representing the approximate opposite of
	 * this color.
	 */
	public Mixed opposite(){
		return new Mixed(255 - this.red, 255 - this.green, 255 - this.blue);
	}
	
	/**
	 * Get this color's red value.
	 * 
	 * @return The value of Red of this color.
	 */
	public int getRed(){
		return this.red;
	}
	
	/**
	 * Get this color's green value.
	 * 
	 * @return The value of Green of this color.
	 */
	public int getGreen(){
		return this.green;
	}
	
	/**
	 * Get this color's blue value.
	 * 
	 * @return The value of Blue of this color.
	 */
	public int getBlue(){
		return this.blue;
	}
}